﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Net;
using ExcelLibrary.SpreadSheet;
using QiHe.CodeLib;
using System.Reflection;
using MAntLibrary.NDEntities;
using MAntLibrary.Utility;
using MAntLibrary;
using MAntLibrary.suppliers;

namespace MAntConsole
{
    public class Program
    {
        static void Main(string[] args)
        {
            /* --------------------- RATAN --------------------- */
            /* Read XML feed */
            FileInfo zahradni_ratan_xml = new FileInfo("zahradni_ratan.xml");
            List<ND_Commodity> ListOfCommodities = new List<ND_Commodity>();
            List<ND_Category> ListOfCategories = new List<ND_Category>();
            Result RESULT = Ratan.ReadXML(zahradni_ratan_xml, ref ListOfCommodities, ref ListOfCategories);

            /* Create XML Import file */
            XML XML = new MAntLibrary.XML();
            XML.Create_XML(ListOfCommodities, "Ratan");
            /* ---------------- END - RATAN -------------------- */


            /* -------------------- DOPPLER -------------------- */
            /* Read XML feed */
            FileInfo doppler_xml = new FileInfo("Heureka_Doppler.xml");
            ListOfCommodities = new List<ND_Commodity>();
            ListOfCategories = new List<ND_Category>();
            Result RESULT2 = Heureka.ReadXML(doppler_xml, ref ListOfCommodities, ref ListOfCategories);

            /* Create XML Import file */
            XML.Create_XML(ListOfCommodities, "Doppler");

            /* Read XSL Export */
            FileInfo fi = new FileInfo("Export_Mares.xls");
            string[,] exportZbozi = IO.ReadXLS(fi, 0);
            string[,] exportKateg = IO.ReadXLS(fi, 1);



            // Create XSL Import File
            //string f = "Ratan-Import.xls";
            //Excel.Create_Excel(f, result, exportKateg, exportZbozi);

            /*         */
            /* DOPPLER */
            /*         */
            List<ND_Category> originCategoryList = IO.ReadXLS2(fi, 1);
            List<ND_Category> newCategoryList = new List<ND_Category>();
            
            /* Read XML Feed */
            FileInfo file2 = new FileInfo("Heureka_Doppler.xml");
            //List<ND_Commodity> result2 = Heureka.ReadXML(file2);


            // NEW
            ND_Category newCat = new ND_Category();
            ND_Category previousCat = new ND_Category();
            int position = 0;
            /*
            foreach (ND_Commodity comm in result2)
            {
                foreach (ND_Category cat in comm.CategoryList)
                {
                    if (ND_Category.IsExist(cat, originCategoryList, ref position)) { previousCat = originCategoryList[position]; newCat = originCategoryList[position]; continue; }
                    else
                    {
                        System.Threading.Thread.CurrentThread.Join(30);
                        string IID = string.Format("K{0}", DateTime.Now.ToString("yyyyMMddHHmmssfffff"));
                        newCat = new ND_Category(0, IID, previousCat.InterniKod, "0", cat.JmenoKategorie, cat.JmenoKategorie);
                        previousCat = newCat;
                        originCategoryList.Add(newCat);
                    }
                }
                comm.Category = newCat;
            }
             * */

            // Create XSL Import File
            //string name = "Doppler-Import.xls";
            //Excel.Create_Excel_Doppler(name, result2, exportZbozi, originCategoryList);

      
            

            Console.WriteLine("DONE.");
            Console.ReadLine();
        }
    }
}
